
import Taro from '@tarojs/taro';
/**
 * 登录校验
 */
export function checkLogin() {
  let data = Taro.getStorageSync("token")
  if (!data) {
    login()
    return false
  } else {
    return true
  }
}

/**
 * 登录
 * @param isBackHome 是否回到首页
 */
export function login(isBackHome = false) {
  const curPages = Taro.getCurrentPages();
  return Taro.reLaunch({
    url: "/pages/welcome/welcome"
  })
  if (curPages[curPages.length - 1].route == 'pages/global-authorized/index') return false
  if (isBackHome) {
    return Taro.reLaunch({
      url: "/pages/global-authorized/index"
    })
  } else {
    return Taro.navigateTo({
      url: "/pages/global-authorized/index"
    })
  }
}

/**
 * 登出
 * @param isBackHome
 */
export async function logout(isBackHome = false) {
  Taro.removeStorageSync("userInfo");
  Taro.removeStorageSync("token");
  login(isBackHome)
}